

package com.hazelcast.internal.serialization.impl.defaultserializers;

import com.hazelcast.internal.serialization.impl.SerializationUtil;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.StreamSerializer;

import java.io.IOException;
import java.util.Map;

/**
 * The {@link Map} serializer
 */
abstract class AbstractMapStreamSerializer<MapType extends Map> implements StreamSerializer<MapType> {

    @Override
    public void write(ObjectDataOutput out, MapType map) throws IOException {
        SerializationUtil.writeMap(map, out);
    }

    MapType deserializeEntries(ObjectDataInput in, int size, MapType result) throws IOException {
        for (int i = 0; i < size; i++) {
            result.put(in.readObject(), in.readObject());
        }
        return result;
    }

}
